#include "utils.h"
#include <stdlib.h>
#include <string.h>

char* malloc_nchar_by_len(int len)
{
    char* p = NULL;
    p = (char* )malloc(len);
    if(!p){
        return NULL;
    }
    memset(p, 0, len);
    return p;
}

void free_nchar(char* p)
{
    if(p){
        free(p);
        p = NULL;
    }
}

char* buftostr(char* buf, int buflen)
{
    char* str = malloc(buflen+1);
    int i = 0;
    memset(str, 0, sizeof(str));
    for (; i < buflen; i++){
        str[i] = buf[i];
    }
    str[i] = '\0';
    return str;
}